<template>
	<view class="page">
		<!-- 地址列表 -->
		<view class="address-list">
			<view class="list" v-for="(item,index) in list" :key="index">
				<view class="name-phone">
					<view class="name">
						<text class="one-omit">{{item.name}}</text>
					</view>
					<view class="phone">
						<text>{{item.mobile}}</text>
						<text v-if="item.is_default" class="tag">默认</text>

					</view>
				</view>
				<view class="address-edit">
					<view class="address">
						<text>{{item.address}}</text>
					</view>
					<view class="edit" @click.stop="onAddressEdit(item)">
						<text class="iconfont icon-edit1"></text>
					</view>
				</view>
			</view>
		</view>
		<!-- 添加地址 -->
		<view class="add-address">
			<view class="btn" @click="onAddressEdit">
				<text>新建收货地址</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {getAddress} from '@/config/api.js'
	export default {
		data() {
			return {
				list: [],
			};
		},
		onLoad(){
			uni.setStorageSync('_address','');
			getAddress().then(data=>{
				this.list = data;
			})
		},
		methods: {
			/**
			 * 编辑地址点击
			 */
			onAddressEdit(data) {
				data && uni.setStorageSync('_address',data);
				uni.navigateTo({
					url: '/moduleB/AddressEdit/AddressEdit',
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	@import 'AddressList.scss';
</style>
